import useSWR from 'swr';
import { getStatisticsDataApi } from '@/app/cg06/api/supplyChainNetwork';
import { useAuthStore } from '@/app/cg06/store/useAuthStore';

export const useStatisticsData = () => {
	const token = useAuthStore(s => s.token);
	const { data, error, isLoading } = useSWR(
		() => (token ? '/big-screen/screen/businessIndicator/globalSupply/refreshStatistics' : null),
		getStatisticsDataApi,
		{
			// circle / 36s
			refreshInterval: 1000 * 3 * 36
		}
	);

	return {
		data: data,
		isLoading,
		isError: error
	};
};

